<template>
  <div class="step-indicator">
    <div class="step-container">
      <div 
        v-for="(step, index) in steps" 
        :key="index"
        class="step-item"
        :class="{ 
          'active': currentStep === index + 1,
          'completed': currentStep > index + 1
        }"
      >
        <div class="step-circle">
          <van-icon v-if="currentStep > index + 1" name="success" />
          <span v-else>{{ index + 1 }}</span>
        </div>
        <div class="step-label">{{ step }}</div>
        <div v-if="index < steps.length - 1" class="step-line"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  steps: {
    type: Array,
    required: true,
    default: () => []
  },
  currentStep: {
    type: Number,
    required: true,
    default: 1
  }
})
</script>

<style scoped lang="scss">
.step-indicator {
  padding: 20px 12px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  
  &::-webkit-scrollbar {
    display: none;
  }
}

.step-container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: relative;
  min-width: fit-content;
  padding: 0 4px;
}

.step-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 60px;
  max-width: 90px;
  
  &:last-child {
    flex: 1;
    min-width: 60px;
  }
}

.step-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f7f8fa;
  border: 3px solid #dcdee0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #969799;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  
  .van-icon {
    font-size: 16px;
    color: #fff;
  }
}

.step-label {
  margin-top: 8px;
  font-size: 11px;
  color: #969799;
  text-align: center;
  transition: all 0.3s;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  hyphens: auto;
  max-width: 100%;
  padding: 0 2px;
}

.step-line {
  position: absolute;
  top: 16px;
  left: 50%;
  right: -50%;
  height: 3px;
  background: #dcdee0;
  transition: all 0.3s;
  z-index: 1;
  border-radius: 2px;
}

.step-item.active {
  .step-circle {
    background: linear-gradient(135deg, #1989fa 0%, #0e6fd6 100%);
    border-color: #1989fa;
    color: #fff;
    box-shadow: 0 4px 12px rgba(25, 137, 250, 0.4);
    animation: pulse 1.5s ease-in-out infinite;
  }
  
  .step-label {
    color: #1989fa;
    font-weight: 600;
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.step-item.completed {
  .step-circle {
    background: linear-gradient(135deg, #07c160 0%, #05a050 100%);
    border-color: #07c160;
    box-shadow: 0 4px 12px rgba(7, 193, 96, 0.3);
    animation: checkmark 0.5s ease-out;
  }
  
  .step-label {
    color: #323233;
    font-weight: 500;
  }
  
  .step-line {
    background: linear-gradient(90deg, #07c160 0%, #05a050 100%);
  }
}

@keyframes checkmark {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
</style>

